import { cn } from '@/lib/utils';
import { InputHTMLAttributes, forwardRef } from 'react';

export interface GlassInputProps extends InputHTMLAttributes<HTMLInputElement> {
  label?: string;
  error?: string;
}

/**
 * GlassInput - Apple-style glassmorphism input field
 * 
 * Features:
 * - Frosted glass effect
 * - Label and error message support
 * - Focus state with glow
 * - Smooth transitions
 */
const GlassInput = forwardRef<HTMLInputElement, GlassInputProps>(
  ({ className, label, error, type = 'text', ...props }, ref) => {
    return (
      <div className="w-full">
        {label && (
          <label className="block text-sm font-semibold bg-gradient-to-r from-indigo-600 to-purple-600 bg-clip-text text-transparent dark:from-indigo-400 dark:to-purple-400 mb-2">
            {label}
          </label>
        )}
        <input
          type={type}
          ref={ref}
          className={cn(
            'w-full px-4 py-3',
            'bg-white/60 dark:bg-white/10 backdrop-blur-md backdrop-saturate-150',
            'border border-gray-300/40 dark:border-white/20 rounded-lg',
            'text-gray-900 dark:text-white placeholder-gray-400 dark:placeholder-white/50',
            'transition-all duration-300',
            'focus:outline-none focus:ring-2 focus:ring-indigo-500/40 dark:focus:ring-white/30 focus:border-indigo-500/50 dark:focus:border-white/40',
            'hover:bg-white/70 dark:hover:bg-white/15',
            'shadow-sm',
            error && 'border-red-400/50 focus:ring-red-400/50',
            className
          )}
          {...props}
        />
        {error && (
          <p className="mt-1 text-sm text-red-500 dark:text-red-300">{error}</p>
        )}
      </div>
    );
  }
);

GlassInput.displayName = 'GlassInput';

export default GlassInput;

